package com.gsn.chooseRoom;

import java.util.ArrayList;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.gsn.dataCommon.ChannelModel;
import com.gsn.dataCommon.ConfigModel;
import com.gsn.dataCommon.UserData;
import com.gsn.poker.asset.FontTexture;
import com.gsn.poker.asset.PokerSound;
import com.gsn.poker.asset.PortalTexture;
import com.gsn.poker.game.MyPoker;
import com.gsn.poker.packet.PacketFactory;

public class ChooseLeaf extends Group {

	public ChooseLeaf() {

	}

	public void init() {
		String array[];
		PortalTexture portalTexture = PortalTexture.inst();

		final ChannelModel current = ConfigModel.getInstance().channelModelList[ConfigModel.getInstance().selectedChannel];
		int numLeaf = current.leafEnd - current.leafStart + 1;
		int num;
		final int channelConvert = ConfigModel.selectedLeaf - current.leafStart;
		int i;
		height = 0;
		for (i = 0; i < numLeaf; i++) {
			num = current.personCount[i];
			final int _i = i;
			Image bgChooseLeaf = new Image(portalTexture.bgChooseLeaf);
			bgChooseLeaf.setClickListener(new ClickListener() {

				@Override
				public void click(Actor actor, float x, float y) {
					// TODO Auto-generated method stub
					PokerSound.playClick();
					if (channelConvert != _i)
						MyPoker.client.send(PacketFactory.chooseLeaf(current.leafStart + _i));
					hide();
				}
			});
			portalTexture.scaleActor(bgChooseLeaf);
			addActor(bgChooseLeaf);
			bgChooseLeaf.y = bgChooseLeaf.height * (numLeaf - i - 1);

			Label labelLeaf = new Label(current.name + " " + (i + 1) + "(" + num + "/" + ConfigModel.maxPerChannel + ")", new Label.LabelStyle(FontTexture.inst().fontMedium, new Color(1, 1, 1, 1)));
			addActor(labelLeaf);

			labelLeaf.y = bgChooseLeaf.y;
			height = height + bgChooseLeaf.height;
		}

	}

	public void show() {
		clear();
		init();
		visible = true;
	}

	public void hide() {
		visible = false;
	}

}
